﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Gui
{
    public class MethodLibrary
    {
         /// <summary>
        /// Returns an array with a predefined size with random numbers 
        /// </summary>
        /// <param name="min">the minimum possible number the array can contain</param>
        /// <param name="max">the maximum possible number the array can contain</param>
        /// <param name="size">Size of the array</param>
        /// <returns></returns>
        public static int[] GenerateArray(int min, int max, int size)
        {
            if(size>15500000)
            {
                
                return GenerateArrayParalell(min, max, size);
            }
            return GenerateArraySequential(min, max, size);
        }
        /// <summary>
        /// Returns an array with a predefined size with random numbers 
        /// </summary>
        /// <param name="min">the minimum possible number the array can contain</param>
        /// <param name="max">the maximum possible number the array can contain</param>
        /// <param name="size">Size of the array</param>
        /// <returns></returns>
        public static int[] GenerateArrayParalell(int min, int max, int size)
        {
            Random r = new Random();
            int[] arr = new int[size];
            Parallel.For(0, arr.Length, i =>
            {
                arr[i] = r.Next(min, max + 1);
                i++;
            });
            
            return arr;
        }

        /// <summary>
        /// Returns an array with a predefined size with random numbers 
        /// </summary>
        /// <param name="min">the minimum possible number the array can contain</param>
        /// <param name="max">the maximum possible number the array can contain</param>
        /// <param name="size">Size of the array</param>
        /// <returns></returns>
        public static int[] GenerateArraySequential(int min, int max, int size)
        {
            Random r = new Random();
            int[] arr = new int[size];
            for (int i = 0; i < arr.Length; i++)
            {
                arr[i] = r.Next(min, max + 1);
            }
            return arr;
        }

        /// <summary>
        /// Returns an array with a predefined size with random numbers 
        /// </summary>
        /// <param name="min">the minimum possible number the array can contain</param>
        /// <param name="max">the maximum possible number the array can contain</param>
        /// <param name="size">Size of the array</param>
        /// <returns></returns>
        public static int[] GenerateArrayAndPrintNumbers(int min, int max, int size)
        {
            int[] arr = GenerateArray(min, max, size);
            Console.WriteLine("Generated an array containing the numbers:");
            bool first = true;
            string str = "";
            foreach (int i in arr)
            {
                Console.Write(str + i);
                if (first)
                    str = " - ";
            }
            Console.WriteLine();
            return arr;
        }
    }
}
